﻿Imports VN.INS.BL.BC
Imports System.Data
Imports System.IO
Imports Microsoft.Office.Interop

Partial Class Devida_Reporte1
    Inherits System.Web.UI.Page

#Region "Constantes"
    Dim tmpChartName1 As String = "test1.jpg"
    Dim tmpChartName2 As String = "test2.jpg"
    Dim tmpChartName3 As String = "test3.jpg"
    Dim tmpChartName4 As String = "test4.jpg"
    Dim tmpChartName5 As String = "test5.jpg"
    Dim tmpChartName6 As String = "test6.jpg"
#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not (Page.IsPostBack)) Then
            Sesion(Session("perfil"))
            Sesion(Session("Persona"))
            CargarSemaforo()
            ListaPPER()
            ListaPeriodo()
            ListaRegion(ddlPPER.SelectedValue.ToString)
            ListaAmbito(ddlPPER.SelectedValue.ToString, ddlRegion.SelectedValue.ToString)
            ListaEjecutor(ddlPPER.SelectedValue.ToString, ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString)
            ListaTipoComponente()
            ListaEspecialista()
            ListaMonitoreador()
            Dim objGeneral As GeneralBC
            Dim strFecha As String = "#"
            Try
                objGeneral = New GeneralBC
                strFecha = objGeneral.FechaAvanceSemanal(ViewState("año"))
                ' Dividimoa la cadena en partes
                If strFecha Is Nothing Then
                    strFecha = ""
                Else
                    Dim words As String() = strFecha.Split(New Char() {"#"c})
                    ' Recorremos todas las partes
                    Dim word As String
                    Dim i As Int16 = 0
                    For Each word In words
                        i = i + 1
                        If i = 2 Then
                            ViewState("Fecha") = word
                            Exit For
                        End If
                    Next
                End If
            Catch ex As Exception
                Throw ex
            End Try
        End If
    End Sub

    Public Sub ListaPPER()
        Dim objPPER As PPERBC
        Dim objData As DataTable
        objPPER = New PPERBC
        objData = New DataTable
        objData = objPPER.ListaPPER("")
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("DESCRIPCION") = "--Todos--"
        drusuariorow("PPER") = ""
        objData.Rows.Add(drusuariorow)
        ddlPPER.DataSource = objData
        ddlPPER.DataTextField = "DESCRIPCION"
        ddlPPER.DataValueField = "PPER"
        ddlPPER.DataBind()
        ddlPPER.SelectedValue = ""
    End Sub

    Public Sub ListaPeriodo()
        Dim objGeneral As GeneralBC
        Dim objData As DataTable
        objGeneral = New GeneralBC
        objData = New DataTable
        objData = objGeneral.ListaPeriodoReporte("0", "DESC", Session("Año"))
        ddlPeriodo.DataSource = objData
        ViewState("Filas") = objData.Rows.Count
        ddlPeriodo.DataTextField = "DESCRIPCION"
        ddlPeriodo.DataValueField = "PERIODO"
        ddlPeriodo.DataBind()
    End Sub

    Public Sub ListaTipoComponente()
        Dim objGeneral As GeneralBC
        Dim objData As DataTable
        objGeneral = New GeneralBC
        objData = New DataTable
        objData = objGeneral.ListaTablaGeneral("TIPO_COMPONENTE")
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("DESCRIPCION") = "--Todos--"
        drusuariorow("CODIGO") = ""
        objData.Rows.Add(drusuariorow)
        ddlTipo.DataSource = objData
        ddlTipo.DataTextField = "DESCRIPCION"
        ddlTipo.DataValueField = "CODIGO"
        ddlTipo.DataBind()
        ddlTipo.SelectedValue = ""
    End Sub

    Public Sub ListaEjecutor(ByVal strPPER As String, ByVal strRegion As String, ByVal strAmbito As String)
        Dim objReporte As ReporteBC
        Dim objData As DataTable
        objReporte = New ReporteBC
        objData = New DataTable
        objData = objReporte.ListaEjecutor(strPPER, strRegion, strAmbito)
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("DESCRIPCION") = "--Todos--"
        drusuariorow("EJECUTOR") = ""
        objData.Rows.Add(drusuariorow)
        ddlEjecutor.DataSource = objData
        ddlEjecutor.DataTextField = "DESCRIPCION"
        ddlEjecutor.DataValueField = "EJECUTOR"
        ddlEjecutor.DataBind()
        ddlEjecutor.SelectedValue = ""
    End Sub

    Public Sub ListaRegion(ByVal strPPER As String)
        Dim objGeneral As GeneralBC
        Dim objData As DataTable
        objGeneral = New GeneralBC
        objData = New DataTable
        objData = objGeneral.ListaRegion(strPPER)
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("NOMBRE") = "--Todos--"
        drusuariorow("UBIGEO") = ""
        objData.Rows.Add(drusuariorow)
        ddlRegion.DataSource = objData
        ddlRegion.DataTextField = "NOMBRE"
        ddlRegion.DataValueField = "UBIGEO"
        ddlRegion.DataBind()
        ddlRegion.SelectedValue = ""
    End Sub

    Public Sub ListaAmbito(ByVal strPPER As String, ByVal strRegion As String)
        Dim objReporte As ReporteBC
        Dim objData As DataTable
        objReporte = New ReporteBC
        objData = New DataTable
        objData = objReporte.ListaAmbito(strPPER, strRegion)
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("DESCRIPCION") = "--Todos--"
        drusuariorow("CODIGO") = ""
        objData.Rows.Add(drusuariorow)
        ddlAmbito.DataSource = objData
        ddlAmbito.DataTextField = "DESCRIPCION"
        ddlAmbito.DataValueField = "CODIGO"
        ddlAmbito.DataBind()
        ddlAmbito.SelectedValue = ""
    End Sub

    Public Sub CargarSemaforo()
        Dim objGeneral As GeneralBC
        Dim objDt As DataTable
        Try
            objGeneral = New GeneralBC
            objDt = New DataTable
            objDt = objGeneral.ListaTablaGeneral("SEMAFORO")
            Dim drusuariorow As DataRow = objDt.NewRow()
            drusuariorow("DESCRIPCION") = "--Todos--"
            drusuariorow("CODIGO") = ""
            objDt.Rows.Add(drusuariorow)
            ddlSemaforo.DataSource = objDt
            ddlSemaforo.DataTextField = "DESCRIPCION"
            ddlSemaforo.DataValueField = "CODIGO"
            ddlSemaforo.DataBind()
            ddlSemaforo.SelectedValue = ""
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub ListaEspecialista()
        Dim objusuario As UsuarioBC
        Dim objData As DataTable
        objusuario = New UsuarioBC
        objData = New DataTable
        objData = objusuario.ListaUsuarioperfil("EP", "")
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("NOMBRE") = "--Todos--"
        drusuariorow("PERSONA") = ""
        objData.Rows.Add(drusuariorow)
        ddlEspecialista.DataSource = objData
        ddlEspecialista.DataTextField = "NOMBRE"
        ddlEspecialista.DataValueField = "PERSONA"
        ddlEspecialista.DataBind()
        ddlEspecialista.SelectedValue = ""        
    End Sub

    Public Sub ListaMonitoreador()
        Dim objusuario As UsuarioBC
        Dim objData As DataTable
        objusuario = New UsuarioBC
        objData = New DataTable
        objData = objusuario.ListaUsuarioperfil("MO", ddlEspecialista.SelectedValue.ToString)
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("NOMBRE") = "--Todos--"
        drusuariorow("PERSONA") = ""
        objData.Rows.Add(drusuariorow)
        ddlMonitoreador.DataSource = objData
        ddlMonitoreador.DataTextField = "NOMBRE"
        ddlMonitoreador.DataValueField = "PERSONA"
        ddlMonitoreador.DataBind()
        ddlMonitoreador.SelectedValue = ""
    End Sub

    Public Sub Chart(ByVal objDt As DataTable, ByVal objDtSem As DataTable)
        'Chart1
        Try
            Dim x() As String = New String(0) {}
            Dim y() As Double = New Double(0) {}
            x(0) = "Al mes"
            y(0) = objDt.Rows(objDt.Rows.Count - 1).Item("DEVENGADO_MES")
            Dim x1() As String = New String(0) {}
            Dim y1() As Double = New Double(0) {}
            x1(0) = "Anual"
            y1(0) = objDt.Rows(objDt.Rows.Count - 1).Item("DEVENGADO_ANUAL")
            Chart1.Series("Avance al mes").Points.DataBindXY(x, y)
            Chart1.Series("Avance al mes").Label = (CDbl(y(0).ToString) * 100).ToString + "%"
            Chart1.Series("Avance al mes").AxisLabel = "Al mes"
            Chart1.Series("Avance Anual").Points.DataBindXY(x1, y1)
            Chart1.Series("Avance Anual").Label = (CDbl(y1(0).ToString) * 100).ToString + "%"
            Chart1.Series("Avance Anual").AxisLabel = "Anual"

            Dim colorSet() As Drawing.Color = New Drawing.Color(1) {}
            colorSet(0) = Drawing.Color.FromArgb(79, 129, 189)
            colorSet(1) = Drawing.Color.FromArgb(217, 150, 148)

            Chart1.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart1.PaletteCustomColors = colorSet
            Chart1.Titles(0).Text = "% Avance Devengado General"
        Catch ex As Exception
            Throw ex
        End Try
        'Chart2
        Try
            Dim x() As String = New String(0) {}
            Dim y() As Double = New Double(0) {}
            x(0) = "Al mes"
            y(0) = objDt.Rows(objDt.Rows.Count - 1).Item("GIRADO_MES")
            Dim x1() As String = New String(0) {}
            Dim y1() As Double = New Double(0) {}
            x1(0) = "Anual"
            y1(0) = objDt.Rows(objDt.Rows.Count - 1).Item("GIRADO_ANUAL")
            Chart2.Series("Avance al mes").Points.DataBindXY(x, y)
            Chart2.Series("Avance al mes").Label = (CDbl(y(0).ToString) * 100).ToString + "%"
            Chart2.Series("Avance Anual").Points.DataBindXY(x1, y1)
            Chart2.Series("Avance Anual").Label = (CDbl(y1(0).ToString) * 100).ToString + "%"

            Dim colorSet() As Drawing.Color = New Drawing.Color(1) {}
            colorSet(0) = Drawing.Color.FromArgb(79, 129, 189)
            colorSet(1) = Drawing.Color.FromArgb(217, 150, 148)

            Chart2.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart2.PaletteCustomColors = colorSet

            Chart2.Titles(0).Text = "% Avance Girado General"
        Catch ex As Exception
            Throw ex
        End Try
        'Chart3
        Try
            Dim x() As String = New String(2) {}
            Dim y() As Double = New Double(2) {}
            Dim x1() As String = New String(2) {}
            Dim y1() As Double = New Double(2) {}
            For i As Int16 = 0 To 2
                Select Case i
                    Case 0
                        x(i) = "PIRDAIS"
                        x1(i) = "PIRDAIS"
                    Case 1
                        x(i) = "PTCD"
                        x1(i) = "PTCD"
                    Case 2
                        x(i) = "PPCOD"
                        x1(i) = "PPCOD"
                End Select
            Next
            For j As Int16 = 0 To objDt.Rows.Count - 1
                If objDt.Rows(j).Item(3).ToString = "PIRDAIS" Then
                    y(0) = objDt.Rows(j).Item("DEVENGADO_MES")
                    y1(0) = objDt.Rows(j).Item("DEVENGADO_ANUAL")
                End If
                If objDt.Rows(j).Item(3).ToString = "PTCD" Then
                    y(1) = objDt.Rows(j).Item("DEVENGADO_MES")
                    y1(1) = objDt.Rows(j).Item("DEVENGADO_ANUAL")
                End If
                If objDt.Rows(j).Item(3).ToString = "PPCOD" Then
                    y(2) = objDt.Rows(j).Item("DEVENGADO_MES")
                    y1(2) = objDt.Rows(j).Item("DEVENGADO_ANUAL")
                End If
            Next
            Chart3.Series("Avance al mes").Points.DataBindXY(x, y)
            Chart3.Series("Avance al mes").Points(0).Label = (CDbl(y(0).ToString) * 100).ToString + "%"
            Chart3.Series("Avance al mes").Points(1).Label = (CDbl(y(1).ToString) * 100).ToString + "%"
            Chart3.Series("Avance al mes").Points(2).Label = (CDbl(y(2).ToString) * 100).ToString + "%"
            Chart3.Series("Avance Anual").Points.DataBindXY(x1, y1)
            Chart3.Series("Avance Anual").Points(0).Label = (CDbl(y1(0).ToString) * 100).ToString + "%"
            Chart3.Series("Avance Anual").Points(1).Label = (CDbl(y1(1).ToString) * 100).ToString + "%"
            Chart3.Series("Avance Anual").Points(2).Label = (CDbl(y1(2).ToString) * 100).ToString + "%"
            Dim colorSet() As Drawing.Color = New Drawing.Color(1) {}
            colorSet(0) = Drawing.Color.FromArgb(79, 129, 189)
            colorSet(1) = Drawing.Color.FromArgb(217, 150, 148)

            Chart3.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart3.PaletteCustomColors = colorSet

            Chart3.Titles(0).Text = "% Avance Devengado por PPER"
        Catch ex As Exception
            Throw ex
        End Try
        'Chart4
        Try
            Dim x() As String = New String(2) {}
            Dim y() As Double = New Double(2) {}
            Dim x1() As String = New String(2) {}
            Dim y1() As Double = New Double(2) {}
            For i As Int16 = 0 To 2
                Select Case i
                    Case 0
                        x(i) = "PIRDAIS"
                        x1(i) = "PIRDAIS"
                    Case 1
                        x(i) = "PTCD"
                        x1(i) = "PTCD"
                    Case 2
                        x(i) = "PPCOD"
                        x1(i) = "PPCOD"
                End Select
            Next
            For j As Int16 = 0 To objDt.Rows.Count - 1
                If objDt.Rows(j).Item(3).ToString = "PIRDAIS" Then
                    y(0) = objDt.Rows(j).Item("GIRADO_MES")
                    y1(0) = objDt.Rows(j).Item("GIRADO_ANUAL")
                End If
                If objDt.Rows(j).Item(3).ToString = "PTCD" Then
                    y(1) = objDt.Rows(j).Item("GIRADO_MES")
                    y1(1) = objDt.Rows(j).Item("GIRADO_ANUAL")
                End If
                If objDt.Rows(j).Item(3).ToString = "PPCOD" Then
                    y(2) = objDt.Rows(j).Item("GIRADO_MES")
                    y1(2) = objDt.Rows(j).Item("GIRADO_ANUAL")
                End If
            Next
            Chart4.Series("Avance al mes").Points.DataBindXY(x, y)
            Chart4.Series("Avance al mes").Points(0).Label = (CDbl(y(0).ToString) * 100).ToString + "%"
            Chart4.Series("Avance al mes").Points(1).Label = (CDbl(y(1).ToString) * 100).ToString + "%"
            Chart4.Series("Avance al mes").Points(2).Label = (CDbl(y(2).ToString) * 100).ToString + "%"
            Chart4.Series("Avance Anual").Points.DataBindXY(x1, y1)
            Chart4.Series("Avance Anual").Points(0).Label = (CDbl(y1(0).ToString) * 100).ToString + "%"
            Chart4.Series("Avance Anual").Points(1).Label = (CDbl(y1(1).ToString) * 100).ToString + "%"
            Chart4.Series("Avance Anual").Points(2).Label = (CDbl(y1(2).ToString) * 100).ToString + "%"

            Dim colorSet() As Drawing.Color = New Drawing.Color(1) {}
            colorSet(0) = Drawing.Color.FromArgb(79, 129, 189)
            colorSet(1) = Drawing.Color.FromArgb(217, 150, 148)

            Chart4.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart4.PaletteCustomColors = colorSet

            Chart4.Titles(0).Text = "% Avance Girado por PPER"

        Catch ex As Exception
            Throw ex
        End Try
        'Chart5
        Try
            Dim x() As String = New String(3) {}
            Dim y() As Double = New Double(3) {}

            x(0) = Format((objDtSem.Rows(objDtSem.Rows.Count - 1).Item("PORC_VERDE")), "p0")
            x(1) = Format((objDtSem.Rows(objDtSem.Rows.Count - 1).Item("PORC_AMBAR")), "p0")
            x(2) = Format((objDtSem.Rows(objDtSem.Rows.Count - 1).Item("PORC_ROJO")), "p0")            
            y(0) = objDtSem.Rows(objDtSem.Rows.Count - 1).Item("PORC_VERDE")
            y(1) = objDtSem.Rows(objDtSem.Rows.Count - 1).Item("PORC_AMBAR")
            y(2) = objDtSem.Rows(objDtSem.Rows.Count - 1).Item("PORC_ROJO")            
            Chart5.Series("SEMAFORO").Points.DataBindXY(x, y)
            Dim colorSet() As Drawing.Color = New Drawing.Color(3) {}
            colorSet(0) = Drawing.Color.FromArgb(155, 187, 89)
            colorSet(1) = Drawing.Color.FromArgb(255, 192, 0)
            colorSet(2) = Drawing.Color.FromArgb(255, 0, 0)

            Chart5.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart5.PaletteCustomColors = colorSet
            Chart5.Titles(0).Text = "Indicador Semáforo todos los PPER"
        Catch ex As Exception
            Throw ex
        End Try
        'Chart6
        Try
            Dim x() As String = New String(2) {}
            Dim y() As Double = New Double(2) {}
            Dim x1() As String = New String(2) {}
            Dim y1() As Double = New Double(2) {}
            Dim x2() As String = New String(2) {}
            Dim y2() As Double = New Double(2) {}
            Dim x3() As String = New String(2) {}
            Dim y3() As Double = New Double(2) {}
            For i As Int16 = 0 To 2
                Select Case i
                    Case 0
                        x(i) = "PIRDAIS"
                        x1(i) = "PIRDAIS"
                        x2(i) = "PIRDAIS"
                        x3(i) = "PIRDAIS"
                    Case 1
                        x(i) = "PTCD"
                        x1(i) = "PTCD"
                        x2(i) = "PTCD"
                        x3(i) = "PTCD"
                    Case 2
                        x(i) = "PPCOD"
                        x1(i) = "PPCOD"
                        x2(i) = "PPCOD"
                        x3(i) = "PPCOD"
                End Select
            Next
            For j As Int16 = 0 To objDtSem.Rows.Count - 1
                If objDtSem.Rows(j).Item(1).ToString = "PIRDAIS" Then
                    y(0) = objDtSem.Rows(j).Item("PORC_VERDE")
                    y1(0) = objDtSem.Rows(j).Item("PORC_AMBAR")
                    y2(0) = objDtSem.Rows(j).Item("PORC_ROJO")                   
                End If
                If objDtSem.Rows(j).Item(1).ToString = "PTCD" Then
                    y(1) = objDtSem.Rows(j).Item("PORC_VERDE")
                    y1(1) = objDtSem.Rows(j).Item("PORC_AMBAR")
                    y2(1) = objDtSem.Rows(j).Item("PORC_ROJO")             
                End If
                If objDtSem.Rows(j).Item(1).ToString = "PPCOD" Then
                    y(2) = objDtSem.Rows(j).Item("PORC_VERDE")
                    y1(2) = objDtSem.Rows(j).Item("PORC_AMBAR")
                    y2(2) = objDtSem.Rows(j).Item("PORC_ROJO")
                End If
            Next
            Chart6.Series("VERDE").Points.DataBindXY(x, y)
            Chart6.Series("VERDE").Points(0).Label = (CDbl(y(0).ToString) * 100).ToString + "%"
            Chart6.Series("VERDE").Points(1).Label = (CDbl(y(1).ToString) * 100).ToString + "%"
            Chart6.Series("VERDE").Points(2).Label = (CDbl(y(2).ToString) * 100).ToString + "%"
            Chart6.Series("AMBAR").Points.DataBindXY(x1, y1)
            Chart6.Series("AMBAR").Points(0).Label = (CDbl(y1(0).ToString) * 100).ToString + "%"
            Chart6.Series("AMBAR").Points(1).Label = (CDbl(y1(1).ToString) * 100).ToString + "%"
            Chart6.Series("AMBAR").Points(2).Label = (CDbl(y1(2).ToString) * 100).ToString + "%"
            Chart6.Series("ROJO").Points.DataBindXY(x2, y2)
            Chart6.Series("ROJO").Points(0).Label = (CDbl(y2(0).ToString) * 100).ToString + "%"
            Chart6.Series("ROJO").Points(1).Label = (CDbl(y2(1).ToString) * 100).ToString + "%"
            Chart6.Series("ROJO").Points(2).Label = (CDbl(y2(2).ToString) * 100).ToString + "%"

            Dim colorSet() As Drawing.Color = New Drawing.Color(3) {}
            colorSet(0) = Drawing.Color.FromArgb(155, 187, 89)
            colorSet(1) = Drawing.Color.FromArgb(255, 192, 0)
            colorSet(2) = Drawing.Color.FromArgb(255, 0, 0)

            Chart6.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart6.PaletteCustomColors = colorSet

            Chart6.Titles(0).Text = "Indicador Semáforo por PPER"

        Catch ex As Exception
            Throw ex
        End Try

        Dim imgPath1 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName1
        Dim imgPath2 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName2
        Dim imgPath3 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName3
        Dim imgPath4 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName4
        Dim imgPath5 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName5
        Dim imgPath6 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName6
        Chart1.SaveImage(imgPath1)
        Chart2.SaveImage(imgPath2)
        Chart3.SaveImage(imgPath3)
        Chart4.SaveImage(imgPath4)
        Chart5.SaveImage(imgPath5)
        Chart6.SaveImage(imgPath6)
    End Sub

    Private Sub ExportarGrilla(ByVal grilla As Table)
        Dim sb As StringBuilder = New StringBuilder()
        Dim sw As StringWriter = New StringWriter(sb)
        Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
        Dim pagina As Page = New Page
        'CREAR TITULO
        Dim gvtitle1 As New Table
        Dim titulo1 As New TableCell()
        titulo1.RowSpan = 1
        titulo1.ColumnSpan = 10
        titulo1.Text = "Reporte sobre programas presupuestales PPER"
        titulo1.Font.Name = "Calibri"
        titulo1.Font.Size = 13
        titulo1.Font.Bold = True
        titulo1.BackColor = Drawing.Color.White
        titulo1.HorizontalAlign = HorizontalAlign.Center
        titulo1.VerticalAlign = VerticalAlign.Middle
        Dim gvtitle2 As New Table
        Dim titulo2 As New TableCell()
        titulo2.RowSpan = 1
        titulo2.ColumnSpan = 10
        titulo2.Text = lblFechaTitulo.Text
        titulo2.Font.Name = "Calibri"
        titulo2.Font.Size = 11
        titulo2.Font.Bold = True
        titulo2.BackColor = Drawing.Color.White
        titulo2.HorizontalAlign = HorizontalAlign.Center
        titulo2.VerticalAlign = VerticalAlign.Middle
        Dim tb1 As New Table
        Dim tit1, tit12 As New TableCell()
        tit1.Text = "PPER: "
        tit1.Font.Name = "Calibri"
        tit1.Font.Size = 11
        tit1.Font.Bold = True
        tit1.BackColor = Drawing.Color.White
        tit1.HorizontalAlign = HorizontalAlign.Left
        tit1.VerticalAlign = VerticalAlign.Middle
        tit12.Text = lblPPER.Text
        Dim tb2 As New Table
        Dim tit2, tit22 As New TableCell()
        tit2.RowSpan = 1
        tit2.Text = "Región: "
        tit2.Font.Name = "Calibri"
        tit2.Font.Size = 11
        tit2.Font.Bold = True
        tit2.BackColor = Drawing.Color.White
        tit2.HorizontalAlign = HorizontalAlign.Left
        tit22.Text = lblRegion.Text
        Dim tb3 As New Table
        Dim tit3, tit32 As New TableCell()
        tit3.RowSpan = 1
        tit3.Text = "Ambito: "
        tit3.Font.Name = "Calibri"
        tit3.Font.Size = 11
        tit3.Font.Bold = True
        tit3.BackColor = Drawing.Color.White
        tit3.HorizontalAlign = HorizontalAlign.Left
        tit3.VerticalAlign = VerticalAlign.Middle
        tit32.Text = lblAmbito.Text
        Dim headertitulo1 As New TableRow()
        headertitulo1.Cells.Add(titulo1)
        Dim headertitulo2 As New TableRow()
        headertitulo2.Cells.Add(titulo2)
        Dim h1 As New TableRow()
        h1.Cells.Add(tit1)
        h1.Cells.Add(tit12)
        Dim h2 As New TableRow()
        h2.Cells.Add(tit2)
        h2.Cells.Add(tit22)
        Dim h3 As New TableRow()
        h3.Cells.Add(tit3)
        h3.Cells.Add(tit32)
        Dim h4 As New TableRow()
        Dim tit4, tit42 As New TableCell()
        tit4.RowSpan = 1
        tit4.Text = "Ejecutor: "
        tit4.Font.Name = "Calibri"
        tit4.Font.Size = 11
        tit4.Font.Bold = True
        tit4.BackColor = Drawing.Color.White
        tit4.HorizontalAlign = HorizontalAlign.Left
        tit4.VerticalAlign = VerticalAlign.Middle
        tit42.Text = lblEjecutor.Text
        h4.Cells.Add(tit4)
        h4.Cells.Add(tit42)
        Dim h5 As New TableRow()
        Dim tit5, tit52 As New TableCell()
        tit5.RowSpan = 1
        tit5.Text = "Tipo de Componente: "
        tit5.Font.Name = "Calibri"
        tit5.Font.Size = 11
        tit5.Font.Bold = True
        tit5.BackColor = Drawing.Color.White
        tit5.HorizontalAlign = HorizontalAlign.Left
        tit5.VerticalAlign = VerticalAlign.Middle
        tit52.Text = lblTipo.Text
        h5.Cells.Add(tit5)
        h5.Cells.Add(tit52)
        Dim h6 As New TableRow()
        Dim tit6, tit62 As New TableCell()
        tit6.RowSpan = 1
        tit6.Text = "Semáforo: "
        tit6.Font.Name = "Calibri"
        tit6.Font.Size = 11
        tit6.Font.Bold = True
        tit6.BackColor = Drawing.Color.White
        tit6.HorizontalAlign = HorizontalAlign.Left
        tit6.VerticalAlign = VerticalAlign.Middle
        tit62.Text = lblSemaforo.Text
        h6.Cells.Add(tit6)
        h6.Cells.Add(tit62)
        Dim h7 As New TableRow()
        Dim tit7, tit72 As New TableCell()
        tit7.RowSpan = 1
        tit7.Text = "Especialista: "
        tit7.Font.Name = "Calibri"
        tit7.Font.Size = 11
        tit7.Font.Bold = True
        tit7.BackColor = Drawing.Color.White
        tit7.HorizontalAlign = HorizontalAlign.Left
        tit7.VerticalAlign = VerticalAlign.Middle
        tit72.Text = lblEspecialista.Text
        h7.Cells.Add(tit7)
        h7.Cells.Add(tit72)
        Dim h8 As New TableRow()
        Dim tit8, tit82 As New TableCell()
        tit8.RowSpan = 1
        tit8.Text = "Monitoreador: "
        tit8.Font.Name = "Calibri"
        tit8.Font.Size = 11
        tit8.Font.Bold = True
        tit8.BackColor = Drawing.Color.White
        tit8.HorizontalAlign = HorizontalAlign.Left
        tit8.VerticalAlign = VerticalAlign.Middle
        tit82.Text = lblMonitoreador.Text
        h8.Cells.Add(tit8)
        h8.Cells.Add(tit82)
        Dim filaVacia As New TableRow()
        Dim celdaVacia As New TableCell
        celdaVacia.Text = ""
        filaVacia.Cells.Add(celdaVacia)
        Dim imgPath1 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName1)
        Dim imgPath2 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName2)
        Dim imgPath3 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName3)
        Dim imgPath4 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName4)
        Dim imgPath5 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName5)
        Dim imgPath6 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName6)
        Dim headerTable As String = "<Table ><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr style='Height:300px;'><td style='width:1000px;'><img src='" + imgPath1 + "' \></td><td></td><td></td><td style='width:500px;'><img src='" + imgPath2 + "' \></td></tr>" + _
                                    "<tr style='Height:300px;'><td style='width:1000px;'><img src='" + imgPath3 + "' \></td><td></td><td></td><td style='width:500px;'><img src='" + imgPath4 + "' \></td></tr>" + _
                                    "</Table>"
        Dim ChartSemaforo As String = "<Table ><tr><td></td><td></td><td></td><td></td></tr><tr><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr style='Height:300px;'><td style='width:1000px;'><img src='" + imgPath5 + "' \></td><td></td><td></td><td style='width:500px;'><img src='" + imgPath6 + "' \></td></tr>" + _
                                    "</Table>"
        gvtitle1.Rows.AddAt(0, headertitulo1)
        gvtitle2.Rows.AddAt(0, headertitulo2)
        tb1.Rows.AddAt(0, h1)
        tb2.Rows.AddAt(0, h2)
        tb3.Rows.Add(h3)
        tb3.Rows.Add(h4)
        tb3.Rows.Add(h5)
        tb3.Rows.Add(h6)
        tb3.Rows.Add(h7)
        tb3.Rows.Add(h8)
        tb3.Rows.Add(filaVacia)
        '------------
        Dim form = New HtmlForm
        pagina.EnableEventValidation = False
        pagina.DesignerInitialize()
        pagina.Controls.Add(form)
        form.Controls.Add(gvtitle1)
        form.Controls.Add(gvtitle2)
        form.Controls.Add(tb1)
        form.Controls.Add(tb2)
        form.Controls.Add(tb3)
        form.Controls.Add(grilla)
        form.Controls.Add(gvPPER)        
        pagina.RenderControl(htw)

        Dim sb1 As StringBuilder = New StringBuilder()
        Dim sw1 As StringWriter = New StringWriter(sb1)
        Dim htw1 As HtmlTextWriter = New HtmlTextWriter(sw1)
        Dim pagina1 As Page = New Page

        Dim Tabla, Tabla1 As New Table
        Dim tRow0, tRow As New TableRow()
        Dim tCell0 As New TableCell()
        tCell0.Text = "Avance Financiero por componente"
        tCell0.Font.Bold = True
        tRow0.Cells.Add(tCell0)
        For row As Int16 = 1 To 11
            Dim tCell As New TableCell()
            If row < 8 Then
                tCell.Text = ""
                'Agregamos celda a la fila
                tRow.Cells.Add(tCell)
            End If
            If (row = 7) Or (row = 9) Then
                tCell.RowSpan = 1
                tCell.ColumnSpan = 2
                Select Case row
                    Case 7
                        tCell.Text = "% Devengado"
                    Case 9
                        tCell.Text = "% Girado"
                End Select
                tCell.HorizontalAlign = 2
                tCell.BackColor = Drawing.Color.FromArgb(220, 230, 241)
                tCell.Font.Bold = True
                tCell.BorderStyle = BorderStyle.Solid
                tCell.BorderColor = Drawing.Color.FromArgb(20, 20, 20)
                tCell.BorderWidth = New Unit(0.5, 2)
                'Agregamos celda a la fila
                tRow.Cells.Add(tCell)
            End If
        Next
        ' Agregamos Fila a la tabla
        Tabla.Rows.Add(tRow0)
        Tabla.Rows.Add(tRow)
        Dim tRowA, tRowB As New TableRow()
        Dim tCellA As New TableCell()
        tCellA.Text = "Indicador semáforo por PPER"
        tCellA.Font.Bold = True
        tRowA.Cells.Add(tCellA)
        For row As Int16 = 1 To 8
            Dim tCellB As New TableCell()
            If row < 2 Then
                tCellB.Text = ""
                'Agregamos celda a la fila
                tRowB.Cells.Add(tCellB)
            End If
            If (row = 2) Or (row = 4) Or (row = 6) Then
                tCellB.RowSpan = 1
                tCellB.ColumnSpan = 2
                Select Case row
                    Case 2
                        tCellB.Text = "VERDE"
                        tCellB.BackColor = Drawing.Color.FromArgb(146, 208, 80)
                    Case 4
                        tCellB.Text = "AMBAR"
                        tCellB.BackColor = Drawing.Color.FromArgb(255, 192, 0)
                    Case 6
                        tCellB.Text = "ROJO"
                        tCellB.BackColor = Drawing.Color.FromArgb(255, 0, 0)                    
                End Select
                tCellB.HorizontalAlign = 2
                tCellB.Font.Bold = True
                tCellB.BorderStyle = BorderStyle.Solid
                tCellB.BorderColor = Drawing.Color.FromArgb(20, 20, 20)
                tCellB.BorderWidth = New Unit(0.5, 2)
                'Agregamos celda a la fila
                tRowB.Cells.Add(tCellB)
            End If
            If row = 8 Then
                tCellB.ColumnSpan = 1
                tCellB.Text = "Total"
                tCellB.BackColor = Drawing.Color.FromArgb(220, 230, 241)
                tCellB.Font.Bold = True
                tCellB.BorderStyle = BorderStyle.Solid
                tCellB.BorderColor = Drawing.Color.FromArgb(20, 20, 20)
                tCellB.BorderWidth = New Unit(0.5, 2)
                tRowB.Cells.Add(tCellB)
            End If
        Next
        ' Agregamos Fila a la tabla
        Tabla1.Rows.Add(filaVacia)
        Tabla1.Rows.Add(tRowA)
        Tabla1.Rows.Add(tRowB)


        Dim form1 = New HtmlForm
        pagina1.EnableEventValidation = False
        pagina1.DesignerInitialize()
        pagina1.Controls.Add(form1)
        form1.Controls.Add(Tabla)
        form1.Controls.Add(gv_Componente)
        form1.Controls.Add(Tabla1)
        form1.Controls.Add(gvSemaforo)
        pagina1.RenderControl(htw1)     
            Response.Clear()
            Response.Buffer = True
            Response.ContentType = "application/vnd.ms-excel"
            Response.AddHeader("Content-Disposition", "attachment;filename=Reporte_" + Now.Date.Year.ToString + Now.Date.Month.ToString + Now.Date.Day.ToString + Now.Hour.ToString + Now.Minute.ToString + Now.Second.ToString + ".xls")
            Response.Charset = "UTF-8"
            Response.ContentEncoding = Encoding.Default
            Response.Write(sb.ToString())
            Response.Write(headerTable)
        Response.Write(sb1.ToString())
            Response.Write(ChartSemaforo)
            Response.End()      
    End Sub

    Protected Sub btnCerrar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnCerrar.Click
        Response.Redirect("Inicio.aspx")      
    End Sub

    Protected Sub btnGenerar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnGenerar.Click
        If ViewState("Filas") > 0 Then
            Generar()
        Else
            alerta.Mostrar_Alerta("Aviso", "No existen datos")
        End If
    End Sub

    Public Sub Generar()
        Me.DivReporte.Style("display") = "inline"
        If ddlPPER.SelectedValue = "PPE-0001" Or ddlPPER.SelectedValue = "" Then

            If Session("Año") = "2012" Then 'Sfb 29/04/2013
                lblComentario.Text = "Si incluye las actividades del D.U. y D.S."
            End If

            If Session("Año") = "2013" Then 'Sfb 29/04/2013
                lblComentario.Text = ""
            End If
        Else
            lblComentario.Text = ""
        End If
        lblFechaTitulo.Text = "Datos al " + ddlPeriodo.SelectedItem.Text

        lblPPER.Text = ddlPPER.SelectedItem.Text
        lblRegion.Text = ddlRegion.SelectedItem.Text
        lblAmbito.Text = ddlAmbito.SelectedItem.Text
        lblEjecutor.Text = ddlEjecutor.SelectedItem.Text
        lblTipo.Text = ddlTipo.SelectedItem.Text
        lblSemaforo.Text = ddlSemaforo.SelectedItem.Text
        lblEspecialista.Text = ddlEspecialista.SelectedItem.Text
        lblMonitoreador.Text = ddlMonitoreador.SelectedItem.Text

        '--------Avance financiero por PPER-------
        Dim objReporte As ReporteBC
        Dim objDt, objDt1 As DataTable
        Try
            objReporte = New ReporteBC
            objDt = New DataTable
            objDt = objReporte.ReporteAFPPER(ddlPPER.SelectedValue.ToString, ddlPeriodo.SelectedValue.ToString, ddlRegion.SelectedValue.ToString, _
                                        ddlAmbito.SelectedValue.ToString, ddlEjecutor.SelectedValue.ToString, ddlTipo.SelectedValue.ToString, _
                                        ddlEspecialista.SelectedValue.ToString, ddlMonitoreador.SelectedValue.ToString, ddlSemaforo.SelectedValue.ToString)
            gvPPER.DataSource = objDt
            gvPPER.DataBind()
        Catch ex As Exception
            Throw ex
        End Try
        '------Avance financiero por componente-----
        Try
            objReporte = New ReporteBC
            objDt1 = New DataTable
            objDt1 = objReporte.Reporte1(ddlPPER.SelectedValue.ToString, ddlPeriodo.SelectedValue.ToString, ddlRegion.SelectedValue.ToString, _
                                        ddlAmbito.SelectedValue.ToString, ddlEjecutor.SelectedValue.ToString, ddlTipo.SelectedValue.ToString, _
                                        ddlEspecialista.SelectedValue.ToString, ddlMonitoreador.SelectedValue.ToString, ddlSemaforo.SelectedValue.ToString)
            gv_Componente.DataSource = objDt1
            gv_Componente.DataBind()
        Catch ex As Exception
            Throw ex
        End Try
        '------Avance financiero por componente-----
        Dim objDtSem As DataTable
        Try
            objDtSem = New DataTable
            objReporte = New ReporteBC
            objDtSem = New DataTable
            objDtSem = objReporte.SemaforoPPER(ddlPPER.SelectedValue.ToString, ddlPeriodo.SelectedValue.ToString, ddlRegion.SelectedValue.ToString, _
                                        ddlAmbito.SelectedValue.ToString, ddlEjecutor.SelectedValue.ToString, ddlTipo.SelectedValue.ToString, _
                                        ddlEspecialista.SelectedValue.ToString, ddlMonitoreador.SelectedValue.ToString, ddlSemaforo.SelectedValue.ToString)
            gvSemaforo.DataSource = objDtSem
            gvSemaforo.DataBind()
        Catch ex As Exception
            Throw ex
        End Try
        '------------CHART------------
        Chart(objDt, objDtSem)
        objDt.Dispose()
        objDt1.Dispose()
        objDtSem.Dispose()
    End Sub

    Protected Sub gv_Componente_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv_Componente.RowDataBound
        For i As Integer = 0 To 9
            e.Row.Cells(i).ForeColor = Drawing.Color.FromArgb(50, 50, 50)
            e.Row.Cells(i).BorderColor = Drawing.Color.FromArgb(50, 50, 50)
            If e.Row.Cells(0).Text = "Total General" Then
                e.Row.Cells(i).ForeColor = Drawing.Color.FromArgb(255, 255, 255)
            Else
                If e.Row.RowType = DataControlRowType.DataRow Then
                    e.Row.Cells(i).BackColor = Drawing.Color.FromArgb(255, 255, 255)
                End If
            End If
        Next

        If e.Row.Cells(0).Text = "Total General" Then
            e.Row.BackColor = Drawing.Color.FromArgb(13, 73, 125)
            e.Row.ForeColor = Drawing.Color.White
            e.Row.Font.Bold = True
        End If
        If e.Row.Cells(2).Text = "Programado al mes reportado" Then
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            e.Row.ForeColor = Drawing.Color.Black
        End If
        If e.Row.Cells(3).Text = "Comprometido" Then
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            e.Row.ForeColor = Drawing.Color.Black
        End If
        If e.Row.Cells(4).Text = "Devengado" Then
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            e.Row.ForeColor = Drawing.Color.Black
        End If
        If e.Row.Cells(5).Text = "Girado" Then
            e.Row.Cells(5).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            e.Row.ForeColor = Drawing.Color.Black
        End If
        If e.Row.Cells(0).Text = "&nbsp;" Then
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(220, 230, 241)
            e.Row.ForeColor = Drawing.Color.Black
        End If
        If e.Row.Cells(7).Text = "Anual" Then
            e.Row.Cells(7).BackColor = Drawing.Color.FromArgb(220, 230, 241)
            e.Row.Cells(9).BackColor = Drawing.Color.FromArgb(220, 230, 241)
            e.Row.ForeColor = Drawing.Color.Black
        End If
        If e.Row.Cells(6).Text = "Al mes" Then
            e.Row.Cells(6).BackColor = Drawing.Color.FromArgb(220, 230, 241)
            e.Row.Cells(8).BackColor = Drawing.Color.FromArgb(220, 230, 241)
            e.Row.ForeColor = Drawing.Color.Black
        End If
        If e.Row.Cells(1).Text = "Presupuesto Modificado" Then
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(220, 230, 241)
            e.Row.ForeColor = Drawing.Color.Black
        End If
    End Sub

    Protected Sub gvPPER_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvPPER.RowDataBound
        For i As Integer = 0 To 9
            e.Row.Cells(i).ForeColor = Drawing.Color.FromArgb(50, 50, 50)
            e.Row.Cells(i).BorderColor = Drawing.Color.FromArgb(90, 90, 90)
            If e.Row.RowType = DataControlRowType.DataRow Then
                e.Row.Cells(i).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            End If
            
            If e.Row.Cells(0).Text = "Total General" Then
                e.Row.Cells(i).BackColor = Drawing.Color.FromArgb(13, 73, 125)
                e.Row.Cells(i).ForeColor = Drawing.Color.White
                e.Row.Cells(i).Font.Bold = True
            End If
            If e.Row.Cells(0).Text = "PIRDAIS" Then
                e.Row.Cells(i).BackColor = Drawing.Color.FromArgb(146, 208, 80)
                e.Row.Cells(i).Font.Bold = True
            End If
            If e.Row.Cells(0).Text = "PTCD" Then
                e.Row.Cells(i).BackColor = Drawing.Color.FromArgb(204, 192, 218)
                e.Row.Cells(i).Font.Bold = True
            End If
            If e.Row.Cells(0).Text = "PPCOD" Then
                e.Row.Cells(i).BackColor = Drawing.Color.FromArgb(183, 222, 232)
                e.Row.Cells(i).Font.Bold = True
            End If
            If e.Row.Cells(2).Text = "Programado al mes reportado" Then
                e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            End If
            If e.Row.Cells(3).Text = "Comprometido" Then
                e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            End If
            If e.Row.Cells(4).Text = "Devengado" Then
                e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            End If
            If e.Row.Cells(5).Text = "Girado" Then
                e.Row.Cells(5).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            End If
            If e.Row.Cells(0).Text = "&nbsp;" Then
                e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(220, 230, 241)
                e.Row.ForeColor = Drawing.Color.Black
            End If
            If e.Row.Cells(7).Text = "Anual" Then
                e.Row.Cells(7).BackColor = Drawing.Color.FromArgb(220, 230, 241)
                e.Row.Cells(9).BackColor = Drawing.Color.FromArgb(220, 230, 241)
                e.Row.ForeColor = Drawing.Color.Black
            End If
            If e.Row.Cells(6).Text = "Al mes" Then
                e.Row.Cells(6).BackColor = Drawing.Color.FromArgb(220, 230, 241)
                e.Row.Cells(8).BackColor = Drawing.Color.FromArgb(220, 230, 241)
                e.Row.ForeColor = Drawing.Color.Black
            End If
            If e.Row.Cells(1).Text = "Presupuesto Modificado" Then
                e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(220, 230, 241)
                e.Row.ForeColor = Drawing.Color.Black
            End If
        Next
    End Sub

    Protected Sub gvSemaforo_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSemaforo.RowDataBound
        For i As Integer = 0 To 7
            e.Row.Cells(i).ForeColor = Drawing.Color.FromArgb(50, 50, 50)
            e.Row.Cells(i).BorderColor = Drawing.Color.FromArgb(90, 90, 90)

            If e.Row.RowType = DataControlRowType.DataRow Then
                e.Row.Cells(i).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            End If
            If e.Row.Cells(0).Text = "Totales" Then
                e.Row.Cells(i).BackColor = Drawing.Color.FromArgb(13, 73, 125)
                e.Row.Cells(i).ForeColor = Drawing.Color.White
                e.Row.Cells(i).Font.Bold = True
            End If
            If e.Row.Cells(0).Text = "PIRDAIS" Then
                e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(146, 208, 80)
                e.Row.Cells(0).Font.Bold = True
            End If
            If e.Row.Cells(0).Text = "PTCD" Then
                e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(204, 192, 218)
                e.Row.Cells(0).Font.Bold = True
            End If
            If e.Row.Cells(0).Text = "PPCOD" Then
                e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(183, 222, 232)
                e.Row.Cells(0).Font.Bold = True
            End If
        Next
    End Sub

    Protected Sub ddlPPER_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPPER.SelectedIndexChanged
        ListaRegion(ddlPPER.SelectedValue.ToString)
        ListaAmbito(ddlPPER.SelectedValue.ToString, ddlRegion.SelectedValue.ToString)
        ListaEjecutor(ddlPPER.SelectedValue.ToString, ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString)
    End Sub

    Protected Sub ddlRegion_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRegion.SelectedIndexChanged
        ListaAmbito(ddlPPER.SelectedValue.ToString, ddlRegion.SelectedValue.ToString)
        ListaEjecutor(ddlPPER.SelectedValue.ToString, ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString)
    End Sub

    Protected Sub ddlAmbito_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlAmbito.SelectedIndexChanged
        ListaEjecutor(ddlPPER.SelectedValue.ToString, ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString)
    End Sub

    Protected Sub ddlEspecialista_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlEspecialista.SelectedIndexChanged
        ListaMonitoreador()
    End Sub

    Protected Sub btnExportar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnExportar.Click
        If gvPPER.Rows.Count = 0 Then
            Exit Sub
        Else
            Dim Tabla As New Table
            Dim titulo1 As New TableCell()
            titulo1.Text = "Avance Financiero por PPER"
            titulo1.Font.Name = "Calibri"
            titulo1.Font.Size = 11
            titulo1.Font.Bold = True
            titulo1.BackColor = Drawing.Color.White
            titulo1.HorizontalAlign = HorizontalAlign.Left
            titulo1.VerticalAlign = VerticalAlign.Middle
            Dim Fila As New TableRow()
            Fila.Cells.AddAt(0, titulo1)
            Tabla.Rows.AddAt(0, Fila)
            Dim tRow As New TableRow()
            For row As Int16 = 1 To 11
                Dim tCell As New TableCell()
                If row < 8 Then
                    tCell.Text = ""
                    'Agregamos celda a la fila
                    tRow.Cells.Add(tCell)
                End If
                If (row = 7) Or (row = 9) Then
                    tCell.RowSpan = 1
                    tCell.ColumnSpan = 2
                    Select Case row
                        Case 7
                            tCell.Text = "% Devengado"
                        Case 9
                            tCell.Text = "% Girado"
                    End Select
                    tCell.HorizontalAlign = 2
                    tCell.BackColor = Drawing.Color.FromArgb(220, 230, 241)
                    tCell.Font.Bold = True
                    tCell.BorderStyle = BorderStyle.Solid
                    tCell.BorderColor = Drawing.Color.FromArgb(20, 20, 20)
                    tCell.BorderWidth = New Unit(0.5, 2)
                    'Agregamos celda a la fila
                    tRow.Cells.Add(tCell)
                End If
            Next
            ' Agregamos Fila a la tabla
            Tabla.Rows.Add(tRow)
            ExportarGrilla(Tabla)
        End If
    End Sub

    'Validacion de sesion
    Public Sub Sesion(ByVal session As Object)
        Dim lost As String
        lost = ""
        If (session Is Nothing) Then lost = "1" Else lost = "0"
        If lost = "1" Then
            Response.Redirect("s_login.aspx?Error=1")
        End If
    End Sub

End Class
